<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


function toArray($object,$type = false){
    $temp = [];
    foreach ($object as $v){
        $temp[] = $v;
    }
    return $type?json_encode($temp):$temp;
}

function formatLink($str){
   if (strpos($str,'./') === 0){
       return substr($str,1);
   }
   return $str;
}



function random_str( $length = 10 ) {
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
    $str = '';
    for ( $i = 0; $i < $length; $i++ )
    {
        $str .= $chars[ mt_rand(0, strlen($chars) - 1) ];
    }
    return $str;
}


function clearSuffix($str,$suffix = NULL){
    if (!is_null($suffix)){
        return str_replace($suffix,'',$str);
    }
    return strchr($str,'.',true);
}


